# -*- coding: utf-8 -*-
# @Time : 2021/9/8 9:32
# @Author : 唐宁
# @Site : 
# @File : FileController.py
# @Software: PyCharm
# file 控制层
import time
from typing import List

from fastapi import APIRouter, File, UploadFile

from config.Result import Result
from config.Setting import settings
from core.order.service.FileService import FileService
from exception.ErrorCodeEnum import ErrorCodeEnum
from exception.ErrorCodeException import ErrorCodeException

file = APIRouter(
    # 控制层前缀
    prefix="/file",
    # swagger 文档模块名称
    tags=["文件模块"]
)


@file.post("/uploadSingleFile", name="上传单个文件样例(存到本地)")
async def uploadSingleFile(bigFile: UploadFile = File(...)):
    """
    上传单个文件
    :param bigFile: 文件信息
    :return: 文件路径
    """
    result = await FileService.saveFileToNative(bigFile)
    return Result(result)


@file.post("/uploadBatchFile", name="上传多个文件样例(存到本地)")
async def uploadBatchFile(bigFiles: List[UploadFile] = File(...)):
    """
    上传多个文件
    :param bigFiles: 文件信息
    :return:  文件路径列表
    """
    return Result([await FileService.saveFileToNative(bigFile) for bigFile in bigFiles])
